#include<bits/stdc++.h>
#define ONLINE_JUDGE
#define ll long long
#define ull unsigned long long
using namespace std;

const ll N = 1e6 + 10, INF = 0x3f3f3f3f;

void solve()
{
    ll n, k;
    cin >> n >> k;
    vector<pair<ll, ll>>a(n);
    for (auto& it : a) cin >> it.first;
    for (auto& it : a) cin >> it.second;
    sort(a.begin(), a.end());

    ll ans, mx, sum = 0;
    priority_queue<ll, vector<ll>, less<ll>> q;
    for (ll i = 0;i < k;i++) {
        q.push(a[i].second);
        sum += a[i].second;
    }
    mx = a[k - 1].first;
    ans = mx * sum;

    for (ll i = k;i < n;i++) {
        ll t = q.top();q.pop();q.push(a[i].second);
        sum = sum - t + a[i].second;
        mx = max(mx, a[i].first);
        ans = min(ans, mx * sum);
    }
    cout << ans << '\n';
}

signed main()
{
    // ios::sync_with_stdio(0);
    // cin.tie(0);cout.tie(0);
#ifndef ONLINE_JUDGE
    std::istringstream in(R"(3
3 2
3 7 6
9 2 4
5 3
6 4 1 5 9
8 6 5 1 7
10 6
61 95 61 57 69 49 46 47 14 43
39 79 48 92 90 76 30 16 30 94
)");
    std::cin.rdbuf(in.rdbuf());
#endif
    ll T = 1;
    cin >> T;
    for (ll i = 1;i <= T;i++) {
        solve();
    }
}